<?php

class spAction
{
	public function action(){
		global $__controller, $__action;
		// 获取当前扩展的配置
		$params = spExt('spAction');
		if( !isset($params[$__controller.'@'.$__action]) )return ;
		
		// 拼装当前地址的唯一参数
		$actionid = $__controller.'@'.$__action;
		if( is_array($params[$__controller.'@'.$__action]) ){
			foreach( $params[$__controller.'@'.$__action] as $arg ){
				$actionid .= '#'.spClass('spArgs')->get($arg);
			}
		}
		// 缓存是否过期
		$cachedata = spAccess('r', $actionid);
		// 没过期，直接显示，直接输出页面，关闭程序
		if( !empty($cachedata) ){
			echo $cachedata;
			@flush();
			exit();
		}
		// 过期或不存在，生成缓存
		@ob_start();
		// 发送缓存名称给router_postfilter
		$GLOBALS['G_SP']['ext_tmp']['spActionID'] = $actionid;
	}
	
	public function cache(){
		if(isset($GLOBALS['G_SP']['ext_tmp']['spActionID'])){
			$cachedata = ob_get_contents();
			spAccess('w', $GLOBALS['G_SP']['ext_tmp']['spActionID'], $cachedata, 3600);
		}
	}
}